home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / ungepackte_daten / 1995 / 7 / 02 / tips&tricks / getscreenmode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-01  |  8.2 KB  |  272 lines

  1. #include <intuition/screens.h>
  2. #include <libraries/asl.h>
  3. #include <clib/exec_protos.h>
  4. #include <clib/graphics_protos.h>
  5. #include <clib/asl_protos.h>
  6. #include <clib/dos_protos.h>
  7.  
  8. static struct Library      *AslBase;
  9. static struct NameInfo      nameinfo;
  10. static struct DimensionInfo dimension;
  11.  
  12. static struct Rectangle     MinMaxSize = { 640,400, 3000,3000 };
  13.  
  14.  
  15. #define FILENAMELEN 256
  16. /*
  17.  *  GetScreenMode  liefert eine DisplayModeID zurück, die der Benutzer
  18.  *                 gewählt hat. Der Funktion muß ein Zeiger auf einen
  19.  *                 Screen übergeben werden. Der Funktion KANN ein Zeiger
  20.  *                 auf ein TagArray übergeben werden, in dem weitere
  21.  *                 Spezifikationen stehen. Damit nimmt einem die Funktion
  22.  *                 alles allgemeine Gedöns ab und läßt einem doch alle
  23.  *                 Freiheiten.
  24.  *
  25.  *  Input          struct Screen *s      Zeiger auf einen Screen
  26.  *                 struct TagList *tl    Zeiger auf ein TagArray
  27.  *                 ULONG *Farben         Zeiger auf ein ULONG, um die
  28.  *                                       Anzahl der gewählten Farben
  29.  *                                       abzulegen. Kann NULL sein.
  30.  *
  31.  *  Output         ULONG DisplayModeID   eine DisplayModeID, wenn der
  32.  *                                       Benutzer etwas gewählt hat
  33.  *                            0          bei Abbruch
  34.  *
  35.  *  Bemerkungen    Die Funktion öffnet und schließt selbst die Asl-
  36.  *                 Library. Es wird mindestens die Version 38 verlangt.
  37.  *
  38.  *  Datum          22. März 1993
  39.  *  letzte Änder.  22. März 1993
  40.  *  Autor          David Göhler
  41.  *
  42.  */
  43.  
  44.  
  45.  
  46. /*
  47.         ASLSM_FilterFunc (struct Hook *) - A function to call for each mode
  48.                         encountered. If the function returns TRUE, the mode is
  49.                         included in the file list, otherwise it is rejected
  50.                         and not displayed. The function receives the following
  51.                         parameters:
  52.                                 A0 - (struct Hook *)
  53.                                 A1 - (ULONG) mode id
  54.                                 A2 - (struct ScreenModeRequester *)
  55.                         (V38)
  56. */
  57.  
  58. /*
  59. __geta4 __regargs ULONG SMFilterFunction(__A0 struct Hook * hooki, __A1 ULONG id,
  60.                                       __A2 struct ScreenModeRequester *SMR)
  61. {
  62.    DisplayInfoHandle Handle;
  63.    ULONG retcode = 0;
  64.  
  65.    if (Handle = FindDisplayInfo(id))
  66.    {
  67.        if ( GetDisplayInfoData (Handle,&dimension,sizeof(dimension),
  68.             DTAG_DIMS,0))
  69.        {
  70.            if ((dimension.Nominal.MaxX <= MinMaxSize.MaxX) &&
  71.                (dimension.Nominal.MaxX >= MinMaxSize.MinX) &&
  72.                (dimension.Nominal.MaxY <= MinMaxSize.MaxY) &&
  73.                (dimension.Nominal.MaxY >= MinMaxSize.MinY))
  74.            {
  75.               retcode = 1;
  76.            }
  77.        }
  78.    }
  79.  
  80.    return retcode;
  81. }
  82. */
  83.  
  84. LONG GetScreenMode(struct Screen *s,struct TagList *tl, ULONG *Farben)
  85. {
  86.    LONG retcode = -1L;
  87.    struct ScreenModeRequester *smr = 0L;
  88.  
  89.    if (s == 0) return retcode;
  90.  
  91.    if (AslBase = OpenLibrary(AslName,38L))
  92.    {
  93.       if (smr = AllocAslRequestTags(ASL_ScreenModeRequest,
  94.                        ASLSM_Screen, s,
  95.                        ASLSM_TitleText, "Bitte ScreenMode wählen:",
  96.                        ASLSM_PositiveText, "Wählen",
  97.                        ASLSM_NegativeText, "Abbrechen",
  98.                        ASLSM_DoDepth, TRUE,
  99.                        ASLSM_DoWidth, TRUE,
  100.                        ASLSM_DoHeight, TRUE,
  101.                        ASLSM_PropertyFlags, DIPF_IS_WB,
  102.                        // ASLSM_FilterFunc, SMFilterFunction,
  103.                        ASLSM_MinWidth, 640L,
  104.                        ASLSM_MinHeight, 400L,
  105.                        // ASLSM_MaxWidth, 800L,
  106.                        // ASLSM_MaxHeight, 600L,
  107.  
  108.                        ASLSM_InitialWidth, 260L,
  109.                        ASLSM_InitialHeight, (s->Height-(s->BarHeight+1)) / 2,
  110.                        ASLSM_InitialLeftEdge, (s->Width-260) / 2,
  111.                        ASLSM_InitialTopEdge, s->BarHeight,
  112.                        TAG_DONE))
  113.       {
  114.          if (AslRequest((APTR)smr,tl)) // wenn, dann hat der User gewählt
  115.          {  retcode = smr->sm_DisplayID;
  116.             if (Farben)
  117.             {  *Farben = smr->sm_DisplayDepth; }
  118.          }
  119.          FreeAslRequest(smr);
  120.       }
  121.       else
  122.       {  // melde("Konnte ScreenModeRequest nicht öffnen",FALSE,0,0);
  123.       }
  124.       CloseLibrary(AslBase);
  125.       AslBase = 0L;
  126.    }
  127.    else
  128.    {  // melde("Konnte asl.library version 38 oder höher nicht öffnen", FALSE,0,0);
  129.    }
  130.  
  131.    return retcode;
  132. }
  133.  
  134.  
  135.  
  136. char *GetNameFromMonitorID(ULONG MonitorID)
  137. {
  138.    DisplayInfoHandle Handle;
  139.    char *retstring = 0;
  140.  
  141.    if (!ModeNotAvailable (MonitorID))
  142.    {
  143.       if (Handle = FindDisplayInfo(MonitorID))
  144.       {
  145.           if ( GetDisplayInfoData (Handle,&nameinfo,sizeof(nameinfo),
  146.                DTAG_NAME,0))
  147.           {
  148.              retstring = nameinfo.Name;
  149.           }
  150.       }
  151.    }
  152.  
  153.    return retstring;
  154. }
  155.  
  156.  
  157. LONG GetMaxDepthFromMonitorID(ULONG MonitorID)
  158. {
  159.    DisplayInfoHandle Handle;
  160.    LONG retcode = 0;
  161.  
  162.    if (!ModeNotAvailable (MonitorID))
  163.    {
  164.       if (Handle = FindDisplayInfo(MonitorID))
  165.       {
  166.           if ( GetDisplayInfoData (Handle,&dimension,sizeof(dimension),
  167.                DTAG_DIMS,0))
  168.           {
  169.              retcode = dimension.MaxDepth;
  170.           }
  171.       }
  172.    }
  173.  
  174.    return retcode;
  175. }
  176.  
  177. BOOL InitNewScreenFromMonitorID(ULONG MonitorID, struct NewScreen *ns)
  178. {
  179.    DisplayInfoHandle Handle;
  180.    BOOL retcode = FALSE;
  181.  
  182.    if (!ModeNotAvailable (MonitorID))
  183.    {
  184.       if (Handle = FindDisplayInfo(MonitorID))
  185.       {
  186.           if ( GetDisplayInfoData (Handle,&dimension,sizeof(dimension),
  187.                DTAG_DIMS,0))
  188.           {
  189.              memset (ns,'\0',sizeof(*ns));
  190.  
  191.              ns->LeftEdge = dimension.Nominal.MinX;
  192.              ns->TopEdge  = dimension.Nominal.MinY;
  193.              ns->Width    = dimension.Nominal.MaxX;
  194.              ns->Height   = dimension.Nominal.MaxY;
  195.  
  196.              //Printf("%ld, %ld, %ld, %ld\n", ns->LeftEdge, ns->TopEdge ,
  197.              //                               ns->Width, ns->Height);
  198.  
  199.              retcode = TRUE;
  200.           }
  201.       }
  202.    }
  203.  
  204.    return retcode;
  205. }
  206.  
  207. /* Syntax  : BOOL DateiReq(filename,AnzeigeText,Show)
  208.  
  209.   Datum   : 04. November 1989
  210.  
  211.   Eingabe : filename     - Zeiger auf den Filenamen
  212.             AnzeigeText  - Zeiger auf Text, der oben im Window steht
  213.             Show         - Ein String, der ein Pattern enthält. Der FileRequester
  214.                            zeigt dann nur Dateien an, die auf das Pattern passen.
  215.  
  216.   Ausgabe : FALSE        - Requester mit Cancel verlassen
  217.             TRUE         - neuer Dateiname ist gültig
  218.  
  219.   Funktion: Aufruf des 2.0-ASL-FileRequesters. Ein vereinfachtes Beispiel.
  220.             Läuft nur unter 2.0
  221. */
  222.  
  223. BOOL DateiReqD(char *filename,char *AnzeigeText,char *Show, BOOL dir)
  224. {
  225.   struct FileRequester *FR;
  226.   char zwfile[FILENAMELEN];
  227.   char zwdir [FILENAMELEN];
  228.   char *cpoint,c;
  229.   BOOL retcode = FALSE;
  230.   ULONG extflags1;
  231.  
  232.   if (dir) extflags1 = FIL1F_NOFILES; else extflags1 = FIL1F_MATCHDIRS;
  233.  
  234.   if (AslBase = (struct Library *)OpenLibrary(AslName,37))
  235.   {
  236.      // String in filename und dirname aufteilen
  237.      cpoint = PathPart(filename);
  238.      c = *cpoint; *cpoint = '\0';
  239.      strcpy(zwdir,filename);
  240.      if (c=='/') {  *cpoint++=c; } else { *cpoint = c; }
  241.      strcpy(zwfile,cpoint);
  242.  
  243.      if (FR = AllocAslRequestTags( ASL_FileRequest,
  244.                                    ASL_Hail,         AnzeigeText,
  245.                                    ASL_Window,       0L,
  246.                                    ASL_File,         zwfile,
  247.                                    ASL_Dir,          zwdir,
  248.                                    ASL_FuncFlags,    FILF_PATGAD,
  249.                                    ASL_ExtFlags1,    extflags1,
  250.                                    ASL_Pattern,      Show,
  251.                                    TAG_DONE ))
  252.      {
  253.         if (RequestFile(FR))
  254.         {
  255.            strcpy(filename,FR->rf_Dir);
  256.            AddPart(filename,FR->rf_File,FILENAMELEN);
  257.            retcode = TRUE;
  258.         }
  259.         FreeFileRequest(FR);
  260.      }
  261.      CloseLibrary((struct Library *)AslBase);
  262.   }
  263.   return retcode;
  264. }
  265.  
  266. BOOL DateiReq(char *filename,char *AnzeigeText,char *Show)
  267. {
  268.     return DateiReqD(filename,AnzeigeText,Show,FALSE);
  269. }
  270.  
  271.  
  272.